<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    .allipse{
        background: linear-gradient();
    }
</style>
<body onload="fn">
    <p>1</p>
    <p>2</p>
    <p>3</p>
    <p>4</p> 
    <p>5</p>
</body>
<script>
    console.log('正常')
    // for(var i = 0;i <5; i++ ){
    
    //     let span =  document.createElement('span');
    //     span.textContent = i;
    //     document.body.appendChild(span)
    //     console.log(i)
    
    // }
    // document.body.addEventListener('load', fn);
    function registerfn (){

        var arr = document.getElementsByTagName('p');
        for(var i = 0;i <arr.length, i++ ;){
        console.log(i+ 2);
            let span =  document.createElement('span');
             span.textContent = i;
             arr[i].onclick = function () {
                 alert(i);
             }
            arr[i].appendChild(span)
            alert(i);
        }
    }
//    (function(){
//        debugger
//         for(var i = 0;i <5, i++; ){
//         console.log(i)
//         // 居然没有任何输出,here should be a semicolon  not comma
//             // window.alert(i);
//         }
//     })()
    

    // fn()
    var numWays = function(n) {
        const arr = [];
        arr[0] = 1;
        arr[1] = 1;
        for (let i = 2; i <= n; i++) {
        arr[i] = arr[i - 1] + arr[i - 2];
        arr[i] = arr[i] % (1e9 + 7);
        }
        return arr[n];
        };

console.log(numWays(50))
    class EvenBus {
        constructor(){
            this.msgList =null
        }
        on(msgName,fn){
            if(!(fn instanceof Function))return
            if(!this.msgList.hasOwnProperty(msgName) ){
                this.msgList[msgName] = [fn]
            }else{
                this.msgList[msgName].push(fn)
            }
        }
        emit(msgName,params){
            if(!this.msgList.hasOwnProperty(msgName) ){

            this.msgList[msgName].forEach(element => {
                element(params)
            });
            }
        }
        off(eventName,fn){
            if(!this.msgList.hasOwnProperty(eventName)) return
            let index = this.msgList[eventName].indexOf(fn)
            if(index <0)return 
            this.msgList[eventName].splice(index,1)
        }
        
    }
    var EventTarget = function () {
        this.listeners = {};
    };
    // 监听事件即注册事件，
    class observer {
        constructor() {
            this.listeners = null
        }
        addEventListener(type, callback) {
            if (!(type in this.listeners)) {
                this.listeners[type] = [];
            }
            this.listeners[type].push(callback);
        };
        removeEventListener = function (type, callback) {
            if (!(type in this.listeners)) {
                return;
            }
            var stack = this.listeners[type];
            for (var i = 0, l = stack.length; i < l; i++) {
                if (stack[i] === callback) {
                    stack.splice(i, 1);
                    return this.removeEventListener(type, callback);
                }
            }
        };

        dispatchEvent(event) {
            if (!(event.type in this.listeners)) {
                return;
            }
            var stack = this.listeners[event.type];
            event.target = this;
            for (var i = 0, l = stack.length; i < l; i++) {
                stack[i].call(this, event);
            }
        };
    }

    // 在不影响原函数的情况下扩展它的能力
    Function.prototype.Decrator = function(fn){
        if(typeof fn !== 'function') return 
        let that = this
        return ()=>{
            that();
            fn(); 
        }
    }
</script>

</html>